package com.itheima;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class demopoi {
    @Test
    public void tes() throws Exception{
        XSSFWorkbook excl= new XSSFWorkbook(new FileInputStream(new File("D:\\学习资料\\笔记\\沈阳五期.xlsx")));
        XSSFSheet sheet=excl.getSheetAt(0);
        for (Row row : sheet) {
            for (Cell cell : row) {
                System.out.println(cell.getStringCellValue());

            }
        }
          excl.close();

    }
    @Test
    public void tes2() throws  Exception{
        XSSFWorkbook excl= new XSSFWorkbook();
        XSSFSheet sheet = excl.createSheet("天黑");
        XSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue("xingming");
        row.createCell(1).setCellValue("nianling");
        row.createCell(2).setCellValue("xingbie");
        XSSFRow row1 = sheet.createRow(1);
        row1.createCell(0).setCellValue("zhangsan");
        row1.createCell(1).setCellValue("20");
        row1.createCell(2).setCellValue("nan");

        FileOutputStream out= new FileOutputStream(new File("D:\\hello.xlsx"));
        excl.write(out);
        excl.close();
    }
}
